package pl.bristleback.server.bristle.binding.resolvers;

import org.apache.log4j.Logger;

/**
 * Creates a Long instance using various methods depending on the given parameter type.
 * <p/>
 * Created on: 2011-04-03 09:39:59 <br/>
 *
 * @author Wojciech Niemiec
 */
public class LongPropertyResolver implements PropertyValueResolver<Long> {
  private static Logger log = Logger.getLogger(LongPropertyResolver.class.getName());

  public Long extractValue(Object value) {
    if (value instanceof Long) {
      return (Long) value;
    } else if (value instanceof Integer) {
      return ((Integer) value).longValue();
    } else if (value instanceof String) {
      try {
        return Long.parseLong((String) value);
      } catch (NumberFormatException e) {
        return null;
      }
    } else {
      return null;
    }
  }
}
